/*
 * Created on Feb 23, 2004
 *
 * Author: Sandeep Prakash
 * Project: Sucxentv2 (using leaf nodes only)
 */
package dbsucxentW.storageEdgeW.loadersW.relationalW;

import java.io.FileWriter;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Enumeration;

import dbsucxentW.storageEdgeW.entitiesW.PathCollection;

/**
 * @author Administrator
 *
 * 
 */
public class PathCollectionRelational extends PathCollection {

	private JdbcOptionsProvider _urlProvider;
	private Connection _dbConnection;
	
	public PathCollectionRelational( JdbcOptionsProvider urlProvider, Connection dbConnection ) {
		super();
		_urlProvider = urlProvider;
		_dbConnection = dbConnection;
		loadPaths();
	}

	/* (non-Javadoc)
	 * @see dbsucxent.storageEdge.entities.PathCollection#loadPaths()
	 */
	public void loadPaths() {
		try{
			loadJDBC();
			Statement stmt = _dbConnection.createStatement();
			ResultSet rs = stmt.executeQuery( "SELECT path_id,path FROM Path" );//SELECT * FROM Path" );
			//Launcher.getLoggerInstance().error( "ok");
			
			while( rs.next() ){
				//Launcher.getLoggerInstance().error( "ok");
				int pathId = rs.getInt( 1 );
				//Launcher.getLoggerInstance().error( "ok");
				if( pathId > _maxId ){
					_maxId = pathId;
					_updateId = pathId;
				}
				
				//Launcher.getLoggerInstance().error( "updated" + pathId + "item " + rs.getString( 3 ) + " size " + _paths.size());
				_paths.put( rs.getString( 2 ), new Integer( pathId ) );
				//Launcher.getLoggerInstance().error( "ok");
			}
			
			rs.close();
			stmt.close();

			//_dbConnection.close();
		}catch( Exception ex ){
			System.exit( 0 );
		}

	}
	
	private void loadJDBC() throws Exception{
		//Class.forName( _urlProvider.driverName() );
		//Launcher.getLoggerInstance().error( _urlProvider.driverName());
		//_dbConnection = DriverManager.getConnection( _urlProvider.jdbcURL(), 
		//								_urlProvider.username(), _urlProvider.password() );
	}
	

}
